﻿using System;
using System.Windows.Forms;

namespace UtfprLibrary.Windows.Forms.ComponentModel {
    /// <summary>
    /// TODO
    /// </summary>
    internal partial class UtfprFormInitialValuedControlCollectionEditor : Form {
        #region Properties

        private UBNInitialValuedControlCollection _validatableCollection;
        /// <summary>
        /// TODO
        /// </summary>
        public UBNInitialValuedControlCollection ValidatableCollection {
            get { return _validatableCollection; }
            set { _validatableCollection = value; }
        }

        private UBNInitialValuedControlCollection _sourceCollection;
        /// <summary>
        /// TODO
        /// </summary>
        public UBNInitialValuedControlCollection SourceCollection {
            get { return _sourceCollection; }
            set { _sourceCollection = value; }
        }

        #endregion

        /// <summary>
        /// TODO
        /// </summary>
        public UtfprFormInitialValuedControlCollectionEditor() {
            InitializeComponent();

            _sourceCollection = new UBNInitialValuedControlCollection();
            _validatableCollection = new UBNInitialValuedControlCollection();
        }

        #region EventHandlers

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmControlToValidateCollection_Load(object sender, EventArgs e) {
            bsSourceCollection.DataSource = _sourceCollection;
            bsInitialValuedCollection.DataSource = _validatableCollection;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstSourceCollection_SelectedIndexChanged(object sender, EventArgs e) {
            propertyGrid.SelectedObject = lstSourceCollection.SelectedItem;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstValidatableCollection_SelectedIndexChanged(object sender, EventArgs e) {
            propertyGrid.SelectedObject = lstInitialValuedCollection.SelectedItem;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e) {
            _sourceCollection = _validatableCollection;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddAll_Click(object sender, EventArgs e) {
            foreach (UtfprInitialValuedControl i in _sourceCollection) {
                bsInitialValuedCollection.Add(i);
            }
            bsSourceCollection.Clear();
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRemoveAll_Click(object sender, EventArgs e) {
            foreach (UtfprInitialValuedControl i in _validatableCollection) {
                bsSourceCollection.Add(i);
            }
            bsInitialValuedCollection.Clear();
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e) {
            try {
                bsInitialValuedCollection.Add(lstSourceCollection.SelectedItem);
                bsSourceCollection.Remove(lstSourceCollection.SelectedItem);
            } catch (Exception) { }
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRemove_Click(object sender, EventArgs e) {
            try {
                bsSourceCollection.Add(lstInitialValuedCollection.SelectedItem);
                bsInitialValuedCollection.Remove(lstInitialValuedCollection.SelectedItem);
            } catch (Exception) { }
        }

        #endregion
    }
}
